﻿  
        try {
            document.execCommand('BackgroundImageCache', false, true);
        } catch(e){}
        
        function executeMenuAction(level)
        {
            var leverArray = level.split("-");
            var menustr = "data.menuList";
            var navigation="";
            for(mi=0;mi<leverArray.length;mi++)
            {
                if(mi==0)
                {
                    menustr=menustr+"["+leverArray[mi]+"]";
                }
                else
                {
                    menustr=menustr+".subMenu["+leverArray[mi]+"]";
                }
                
                if(mi == 0)
                {
                    navigation = eval(menustr+".menuName");
                }
                else
                {
                    navigation = navigation + ">" + eval(menustr+".menuName");
                }
            }
           
            if(data.highlightedSubNav != "")
            {
                data.highlightedSubNav.attributes["class"].value = data.highlightedSubNavOriginalClass;
            }

            updateTitleBar(navigation);
            
            data.highlightedSubNav = data.currentSubNav;
            data.hoveredSubNav = data.currentSubNav;
            
            if(data.currentSubNav.attributes["class"].value == "xin3hover")
            {
                data.highlightedSubNavOriginalClass = "";
            }
            else 
            {
                data.highlightedSubNavOriginalClass = "xin3";
            }
            
            if(leverArray.length > 2)
            {
               data.currentSubNav.attributes["class"].value = "xin2";
            }
            else
            {
               data.currentSubNav.attributes["class"].value = "xin4";
            }
            data.hoveredSubNavOriginalClass = data.currentSubNav.attributes["class"].value;
            var menu = eval(menustr);
            
            if(menu.actionList.length>1)
            {
                document.getElementById('relFuncFrame').src= data.webpath + "/" + menu.actionList[1].actionName + ".asp";
            }
            
            if(menu.actionList.length>0)
            {
               menuActionForm.action = data.webpath + "/" + menu.actionList[0].actionName + ".asp" ;
               menuActionForm.submit();
            }
        }

        function updateTitleBar(quickMenuName) 
        {
            document.getElementById('locationArea').innerHTML = "<H3>您现在的位置是：" + quickMenuName + "</H3>";
        }
        
        function updateTitleBarAndClearHighlightedSubNav(quickMenuName)
        {
            
            if(data.highlightedSubNav != null && data.highlightedSubNav.attributes != null)
            {
                data.highlightedSubNav.attributes["class"].value = data.highlightedSubNavOriginalClass;
                data.hoveredSubNavOriginalClass = data.highlightedSubNavOriginalClass;
            }
            updateTitleBar(quickMenuName);
        }
        
      
        
        function comfirmlogout() 
        {
            if(confirm("是否确定要退出中国农业银行网上银行系统？"))
            {
                
                window.onbeforeunload = null;
                window.close();
            }
            else
            {
                //window.onbeforeunload = doOnBeforeUnload;
            }
        }
        
       function doOnBeforeUnload() 
       {
		    return '欢迎您再次使用中国农业银行网上银行。'
	    }
	
	    
	    //window.onbeforeunload=doOnBeforeUnload;
        window.onunload = DoLogOut;
        function DoLogOut()
        {           
	        //ebf.ajax.AjaxHelper.executeEbfAction("SignOffSessionActionAct","closeActionDiv");
        }
        
        function layoutContentFrame(contentFrame)
        {
            contentFrame.style.display="block";
            contentFrame.style.width="100%";
            contentFrame.style.height="100%";
            
            contentFrame.contentWindow.document.body.style.overflowY = "auto";
            contentFrame.contentWindow.document.body.style.overflowX = "hidden";
            contentFrame.contentWindow.document.body.attachEvent('onclick', function() 
            { 	
	            var e=contentFrame.contentWindow.event;
  	            var srcE=e.srcElement?e.srcElement:e.target;
  	            if(!checkIfIdExistInAncestors(srcE, "subMenu2Div"))
  	            {
  	                if(!checkIfIdExistInAncestors(srcE, "subMenuDiv"))
  	                {
	                    hideSubMenus();
  	                }
  	            }
            });
            
        }
         var fillHTML = function(el, htmlCode) {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
            htmlCode = '<div style="display:none;" >for ie</div>' + htmlCode;
            htmlCode = htmlCode.replace(/<script([^>]*)>/g,
                                    '<script$1 defer>');
            el.innerHTML = htmlCode + '<iframe  height="100%" style="position: absolute; z-index: -1; width: 100%;  top: 0; left: 0; scrolling: no;" frameborder="0" src="' + data.webpath + "/" + 'entrance/blank.htm"></iframe>';
            //TODO: remove this workaround later
            el.childNodes[2].style.height = el.childNodes[1].offsetHeight;
            el.removeChild(el.firstChild);
        }
        else {
            var el_next = el.nextSibling;
            var el_parent = el.parentNode;
            el_parent.removeChild(el);
            el.innerHTML = htmlCode + '<iframe height="100%" style="position: absolute; z-index: -1; width: 100%; top: 0; left: 0; scrolling: no;" frameborder="0" src="' + data.webpath + "/" + 'entrance/blank.htm"></iframe>';
            //el.innerHTML = htmlCode;
            if (el_next) {
                el_parent.insertBefore(el, el_next)
            } else {
                el_parent.appendChild(el);
            }
        }
    }

    function selectNavMenuItem(navPart) {
        data.currentNav.attributes["class"].nodeValue = "";
        data.currentNav = navPart.parentNode;
        data.currentNav.attributes["class"].nodeValue = "xin1";
        
        if(data.menuCache[navPart.hierarchy] == null)
        {
            
            var subNavData = data.menuList[navPart.hierarchy].subMenu;
            subNavData["parentHierarchy"] = navPart.hierarchy;
            var templateValue = data.subNavTemplateEngine.execute(subNavData);
            
            data.menuCache[navPart.hierarchy] = templateValue;
        }
        
        fillHTML(document.getElementById("subNavDiv"), data.menuCache[navPart.hierarchy]);
        
        data.currentScrollNav = data.currentNav;
        data.currentScrollSubNav = document.getElementById("subNavDiv").childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        initializeTrundle();
    }

    
    function selectSubNavMenuItem(subNavPart) {
        data.currentSubNav = subNavPart.parentNode;
        
        var hierarchy = subNavPart.hierarchy.split("-");
        var subMenuData = data.menuList[hierarchy[0]];
        for (var i = 1; i < hierarchy.length; i++) {
            subMenuData = subMenuData.subMenu[hierarchy[i]]
        }

        if (subMenuData.subMenu.length != 0) {
            if(data.currentSubNav.attributes["class"].nodeValue != "xin2"){
                if(data.hoveredSubNav.attributes != null && data.hoveredSubNav.attributes["class"].nodeValue == "xin3hover")
                {
                    data.hoveredSubNav.attributes["class"].nodeValue = "";
                }
                
                data.hoveredSubNav = data.currentSubNav;
                data.hoveredSubNavOriginalClass = "";
                data.currentSubNav.attributes["class"].nodeValue = "xin3hover";
            }
            
        
            if(data.menuCache[subNavPart.hierarchy] == null)
            {
                subMenuData = subMenuData.subMenu;
                subMenuData.parentHierarchy = subNavPart.hierarchy;
                var templateValue = data.subMenuTemplateEngine.execute(subMenuData);
                data.menuCache[subNavPart.hierarchy] = templateValue;
            }
            
            var subMenuDiv = document.getElementById("subMenuDiv");
            
            subMenuDiv.style.display = "";
            subMenuDiv.style.width="";
            subMenuDiv.style.height="";
            
//            subMenuDiv.innerHTML = data.menuCache[subNavPart.hierarchy];
            fillHTML(subMenuDiv, data.menuCache[subNavPart.hierarchy]);
            
            var position = getDim(subNavPart);
            subMenuDiv.style.filter = "progid:DXImageTransform.Microsoft.dropShadow(Color=a7c1c0,offX=3,offY=2,positive=true) progid:DXImageTransform.Microsoft.Alpha(opacity=90);"
            subMenuDiv.style.posLeft = position.x;
            subMenuDiv.style.posTop = position.y + subNavPart.offsetHeight + 3;
            subMenuDiv.style.width = subMenuDiv.scrollWidth;
            subMenuDiv.style.height = subMenuDiv.scrollHeight;
            //animation
        }
    }

    function selectSubMenuItem(subMenuPart) {
    
        data.currentSubMenu = subMenuPart;
        var hierarchy = subMenuPart.hierarchy.split("-");
        var subMenuData = data.menuList[hierarchy[0]];
        for (var i = 1; i < hierarchy.length; i++) {
            subMenuData = subMenuData.subMenu[hierarchy[i]]
        }
        
        if (subMenuData.subMenu.length != 0) {
            if(data.menuCache[subMenuPart.hierarchy] == null) {
                subMenuData = subMenuData.subMenu;
                subMenuData.parentHierarchy = subMenuPart.hierarchy;
                var templateValue = data.subMenu2TemplateEngine.execute(subMenuData);
                
                data.menuCache[subMenuPart.hierarchy] = templateValue;
            }

            var position = getDim(subMenuPart);
            var subMenu2Div = document.getElementById("subMenu2Div");
            subMenu2Div.style.posLeft = position.x + subMenuPart.parentNode.offsetWidth - 2;
            subMenu2Div.style.posTop = position.y;
            subMenu2Div.style.display = "";
            subMenu2Div.style.width = "";
            subMenu2Div.style.height = "";
            fillHTML(subMenu2Div, data.menuCache[subMenuPart.hierarchy]);
            
            subMenu2Div.style.filter = "progid:DXImageTransform.Microsoft.dropShadow(Color=a7c1c0,offX=3,offY=2,positive= true) progid:DXImageTransform.Microsoft.Alpha(opacity=87);"
            subMenu2Div.style.width = subMenu2Div.offsetWidth - 3;
            subMenu2Div.style.height = subMenu2Div.offsetHeight -2;
        }
        else
        {
            hideSubMenu2();
        }
    }

    function getScroll(o) {
        o = o || null;
        if (o != null && typeof o == 'object') {
            var w = o.window;
            var d = o.document;
        }
        else {
            var w = window;
            var d = document;
        }
        var dd = d.documentElement;
        var L = 0, T = 0;
        L = (w.pageXOffset) ? w.pageXOffset : ((dd && dd.scrollLeft) ? dd.scrollLeft : (d.body ? d.body.scrollLeft : 0));
        T = (w.pageYOffset) ? w.pageYOffset : ((dd && dd.scrollTop) ? dd.scrollTop : (d.body ? d.body.scrollTop : 0));
        w = d = dd = null;
        return { "left": L, "top": T };
    }

    function getDim(htmlObj) {

        var rd = { x: 0, y: 0 }
        do {
            rd.x += htmlObj.offsetLeft //获得对象相对于上级（父）对象的位置坐标  
            rd.y += htmlObj.offsetTop
            htmlObj = htmlObj.offsetParent //上传到上级（父）对象  
        } while (htmlObj)

        var scroll = getScroll(htmlObj);
        rd.x -= scroll.left;
        rd.y -= scroll.top;

        return rd
    }


    function navScrollLeft() {
        data.currentScrollNav.style.display = "none";
        if(data.currentScrollNav.nextSibling != null && data.currentScrollNav.nextSibling.tagName == "LI"){
            data.currentScrollNav = data.currentScrollNav.nextSibling;
        }
    }
    
    function navScrollRight() {
        if(data.currentScrollNav.previousSibling != null && data.currentScrollNav.previousSibling.tagName == "LI"){
            data.currentScrollNav = data.currentScrollNav.previousSibling;
            data.currentScrollNav.style.display = "";
        }
    }
    
    function subNavScrollLeft() {
        data.currentScrollSubNav.style.display = "none";
        if(data.currentScrollSubNav.nextSibling != null && data.currentScrollSubNav.nextSibling.tagName == "LI"){
            data.currentScrollSubNav = data.currentScrollSubNav.nextSibling;
        }
    }
    
    function subNavScrollRight() {
        if(data.currentScrollSubNav.previousSibling != null && data.currentScrollSubNav.previousSibling.tagName == "LI"){
            data.currentScrollSubNav = data.currentScrollSubNav.previousSibling;
            data.currentScrollSubNav.style.display = "";
        }
    }
    
    function hideSubMenu2()
    {
        document.getElementById("subMenu2Div").style.display = "none";
    }
    
    function subNavMouseOut(){
        var o = window.event.fromElement;
        while (o) {
            if (o.tagName == "LI") {
                o = window.event.toElement;
                if(o == null  || o.tagName == "LI") {
                    break;
                }
                else {
                    return;
                }
            }
            o = o.parentNode;
        }
        
        
        hideSubMenus();
    }
    
      function hideSubMenus(){
        if(data.hoveredSubNav != null && data.hoveredSubNav.attributes != null)
        {
            data.hoveredSubNav.attributes["class"].value = data.hoveredSubNavOriginalClass;
        }
        
        document.getElementById("subMenuDiv").style.display = "none";
        document.getElementById("subMenu2Div").style.display = "none";
    }
    
    function preloadImages()
    {
        
        if (document.images)
        {
          preload_image_object = new Image();
          image_url = new Array();
          image_url[0] = data.webpath + "/images/kongge.gif";
          image_url[1] = data.webpath + "/images/elegant_submenu-bg01L.gif";
          image_url[2] = data.webpath + "/images/elegant_submenu-bg01M.gif";
          image_url[3] = data.webpath + "/images/elegant_submenu-bg01R.gif";
          image_url[4] = data.webpath + "/images/elegant_submenu-bg02L.gif";
          image_url[5] = data.webpath + "/images/elegant_submenu-bg02R.gif";
          image_url[6] = data.webpath + "/images/elegant_submenu-bg03L.gif";
          image_url[7] = data.webpath + "/images/elegant_submenu-bg03M.gif";
          image_url[8] = data.webpath + "/images/elegant_submenu-bg03R.gif";
          image_url[9] = data.webpath + "/images/elegant_subnav_onright.gif";

           var i = 0;
           for(i = 0; i <= 9; i++) 
             preload_image_object.src = image_url[i];
        } 
      
    }
    
    function initialize()
    {
    
        preloadImages();        
        data.navTemplateEngine = new ebf.util.TemplateEngine(menuTemplates.document.getElementById("navTemplate").value);
        
        data.subNavTemplateEngine = new ebf.util.TemplateEngine(menuTemplates.document.getElementById("subNavTemplate").value);
        
        data.subMenuTemplateEngine = new ebf.util.TemplateEngine(menuTemplates.document.getElementById("subMenuTemplate").value);
        data.subMenu2TemplateEngine = new ebf.util.TemplateEngine(menuTemplates.document.getElementById("subMenu2Template").value);
        
       
        var ccc = data.navTemplateEngine.execute(data);
        fillHTML(document.getElementById("navDiv"), ccc);
        data.currentNav = document.getElementById("navDiv").childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        selectNavMenuItem(data.currentNav.firstChild);
        
        //document.onmouseup = hideMenus();
        document.onclick = function() 
        { 	
	        var e=window.event;
  	        var srcE=e.srcElement?e.srcElement:e.target;
  	        if(!checkIfIdExistInAncestors(srcE, "subMenu2Div"))
  	        {
  	            if(!checkIfIdExistInAncestors(srcE, "subMenuDiv"))
  	            {
	                hideSubMenus();
  	            }
  	        }
        }
        
           document.getElementById("navDiv").onmouseover = function() {
        hideSubMenus();
    }
    
    document.getElementById("subMenuDiv").onmouseout = function() {

        var o = window.event.fromElement;
        while (o) {
            if (o == document.getElementById("subMenuDiv")) {
                o = window.event.toElement;
                while (o) {
                    if ((o == document.getElementById("subMenuDiv")) || (o == document.getElementById("subMenu2Div"))) {
                        return;
                    }
                    o = o.parentNode;
                }
                break;
            }
            o = o.parentNode;
        }
        hideSubMenus();
    }

    document.getElementById("subMenu2Div").onmouseout = function() {
        var o = window.event.fromElement;
        if (window.event.toElement == null) {
            return;
        }

        while (o) {
            if (o == document.getElementById("subMenu2Div")) {
                o = window.event.toElement;
                while (o) {
                    if ((o == document.getElementById("subMenu2Div"))) {
                        return;
                    }
                    o = o.parentNode;
                }
                break;
            }
            o = o.parentNode;
        }
        data.currentSubMenu.parentNode.className = "xin5";
        document.getElementById("subMenu2Div").style.display = "none";
    }
        
        
        initializeTrundle();
        window.onresize = resizeMenu;
    }
    
    function initializeTrundle(){
        
        if(data.currentScrollNav.parentNode.offsetHeight > 24)
        {
            document.getElementById("navTrundle").style.display = "";
        } 
        else if (data.currentScrollNav.parentNode.firstChild != data.currentScrollNav)
        {
            var divWidth = data.currentScrollNav.parentNode.parentNode.offsetWidth;
            var ulWidth = data.currentScrollNav.parentNode.offsetWidth;
            var firstHiddenNav = data.currentScrollNav.previousSibling;
            while(divWidth - ulWidth > firstHiddenNav.scrollWidth + 15)
            {
                firstHiddenNav.style.display = "";
                data.currentScrollNav = firstHiddenNav;
                
                if(firstHiddenNav.previousSibling == null)
                {
                    document.getElementById("navTrundle").style.display = "none";
                    break;
                }
                else
                {
                    firstHiddenNav = firstHiddenNav.previousSibling;
                }
            }
        } 
        else {
            document.getElementById("navTrundle").style.display = "none";
        }
        
        
        if(data.currentScrollSubNav.parentNode.offsetHeight > 24)
        {
            document.getElementById("subNavTrundle").style.display = "";
        } 
        else if (data.currentScrollSubNav.parentNode.firstChild != data.currentScrollSubNav)
        {
            var divWidth = data.currentScrollSubNav.parentNode.parentNode.offsetWidth;
            var ulWidth = data.currentScrollSubNav.parentNode.offsetWidth;
            var firstHiddenNav = data.currentScrollSubNav.previousSibling;
            while(divWidth - ulWidth > firstHiddenNav.scrollWidth + 15)
            {
                firstHiddenNav.style.display = "";
                data.currentScrollSubNav = firstHiddenNav;
                
                if(firstHiddenNav.previousSibling == null)
                {
                    document.getElementById("subNavTrundle").style.display = "none";
                    break;
                }
                else
                {
                    firstHiddenNav = firstHiddenNav.previousSibling;
                }
            }
        } 
        else {
            document.getElementById("subNavTrundle").style.display = "none";
        }
    }
    
    function resizeMenu(){
        initializeTrundle();
    }

    function checkIfIdExistInAncestors(element, id)
    {
	     var currentElement = element;
	     var flag = false;
	     while (currentElement.parentElement)
	     {
 		     if(id == currentElement.id)
 		     {
 		 		 flag = true;
 		         break;
 		     }
	         currentElement = currentElement.parentElement;
	     }
	     if(!flag)
	     {
	        document.getElementById(id).style.display='none';
	     }
	     return flag;
    }

